package com.apobates.jforum.grief.aurl.selector;

import com.apobates.jforum.grief.aurl.core.AUrlMeta;
import java.util.Collection;
import java.util.List;
/**
 * 域名选择器
 */
public class DomainStringSelector extends AUrlMetaGeneralSelector{
    public DomainStringSelector(AUrlMeta rawMeta) {
        super(rawMeta);
    }

    @Override
    public Collection<String> getResult() {
        final AUrlMeta ins = getRawMeta();
        StringBuilder domainBuilder = new StringBuilder();
        if (ins.getScheme() != null) {
            domainBuilder.append(ins.getScheme()).append(':');
        }
        final String uiStr = ins.getUserInfo();
        final String hostStr = ins.getHost();
        final String posrtStr = ins.getPort();
        if (uiStr != null || hostStr != null) {
            domainBuilder.append("//");
            if (uiStr != null) {
                domainBuilder.append(uiStr).append('@');
            }
            if (hostStr != null) {
                domainBuilder.append(hostStr);
            }
            if (isAppendPort(posrtStr)) {
                domainBuilder.append(':').append(posrtStr);
            }
        }
        return List.of(domainBuilder.toString());
    }
}
